<template>
	<view>
		<view class="container">
			<view class="activeDetail">
				<view class="activeDetail-title">
					<text class="article-title">{{detail.title}}</text>				
				</view>
				<view class="team-tit">发布人：{{detail.userName}}</view>
				<view class="team-tit">公告类型：{{detail.publicItem | optionsFilter(publicOptions)}}</view>
				<view class="team-tit">有效时间：{{detail.publicDate | dateFormat('yyyy-MM-dd')}} 至 {{detail.loseDate | dateFormat('yyyy-MM-dd')}}</view>
				<view class="article-line"></view>
				
				<view class="activeDetail-img" v-if="detail.picture">
					<image :src="$getImg(detail.picture)"></image>
				</view>
				
				<rich-text class="activeDetail-info" :nodes="detail.content">
				</rich-text>
				
				<view class="article-line"></view>
				<view>
					<p>附件</p>
					<p><file-list :files="attachments"></file-list></p>
				</view>
				
			</view>
		</view>
	</view>
</template>

<script>
	import FileList from '@/components/expand/file-list.vue'
	import { getNoticeDetail, getAttachment } from '@/api/common.js'
	import constants from '@/utils/constants.js'
	
	export default {
		components: {
			FileList
		},
		onLoad(params) {
			this.noticeId = params.noticeId
			this.loadData()
		},
		data() {
			return {
				noticeId: '',
				detail: {},
				attachmentIds: [],
				attachments: [],
				publicOptions: constants.publicOptions
			}
		},
		methods: {
			loadData() {
				getNoticeDetail(this.noticeId).then(res => {
					this.detail = res.data
					if(res.data.fileAttach){
						res.data.fileAttach.split(",").forEach(item=>{
							this.attachmentIds.push(item)
						})
						this.getAttachment()
					}
				})
			},
			getAttachment() {
				getAttachment(this.attachmentIds).then(res=>{
					this.attachmentIds.forEach(item=>{
						let data = res.data[item]
						this.attachments.push({
							ext: data.ext,
							file_name: data.fileName,
							file_id: data.id,
							file_size: data.totalBytes
						})
					})
				})
			},
		}
	}
</script>

<style lang="scss">
	.container {		
		background-color: #fff;
	}
	
	.activeDetail {
		padding: 40rpx 30rpx;
		display: flex;
		flex-direction: column;
		
		.activeDetail-title {
			display: flex;
			flex-direction: column;
			
			.article-title {
				font-size: $app-font-size-big + 8rpx;
			}
			
			.article-date {
				margin-top: 20rpx;
				color: $app-font-color-subtitle;
			}
		}
		
		.activeDetail-img {
			//margin-top: 40rpx;
			
			image {
				height: 400rpx;
				width: 100%;
				margin-bottom: 20rpx;
			}
		}
		
		.article-line {
			margin: 30rpx 0;
			height: 1px;
			width: 100%;
			background-color: #eeeeee;
		}
	}
	.team-tit{ font-size:13px; color:#999; margin-top: 5px;}
</style>
